<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<!--库存修改模态框-->
<div class="modal fade" id="modal-create">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">库存信息编辑</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" role="form">
                    <input type="hidden" class="form-control" id="ityId" name="ityId">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-right">项目名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="ityProName" name="ityProName" autocomplete="off"
                                   placeholder="请输入项目名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-right">特殊说明</label>
                        <div class="col-sm-10">
                            <input type="text" autocomplete="off" class="form-control" id="itySpec" name="itySpec"
                                   placeholder="请输入特殊说明">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-right">回货时间</label>
                        <div class="col-sm-10">
                            <input type="text" autocomplete="off" class="form-control" name="ityBackDate"
                                   id="ityBackDate" placeholder="请输入回货时间">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-editInventory">确定</button>
            </div>
        </div>
    </div>
</div>

<section class="content-header">
    <h1>库存信息编辑</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="ityProCode"
                                           class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="ityProName"
                                           class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>特殊说明</label>
                                    <input type="text" name="itySpec"
                                           class="form-control"
                                           placeholder="请输入特殊说明">
                                </div>
                                <div class="form-group">
                                    <label>跟踪号</label>
                                    <input type="text" name="ityTrackCode" class="form-control"
                                           placeholder="请输入跟踪号">
                                </div>
                                <div class="form-group">
                                    <label>原料类型</label>
                                    <input type="text" name="matTypeName" class="form-control"
                                           placeholder="请输入原料类型">
                                </div>
                                <div class="form-group">
                                    <label>原料材质</label>
                                    <input type="text" name="matQualityName" class="form-control"
                                           placeholder="请输入原料材质">
                                </div>
                                <div class="form-group">
                                    <label>原料规格</label>
                                    <input type="text" name="matSpecName" class="form-control"
                                           placeholder="请输入原料规格">
                                </div>
                                <div class="form-group">
                                    <label>宽度</label>
                                    <input type="number" step="0.1" name="matWidth"
                                           class="form-control"
                                           placeholder="请输入原料宽度">
                                </div>
                                <div class="form-group">
                                    <label>长度</label>
                                    <input type="number" step="0.1" name="matLength"
                                           class="form-control"
                                           placeholder="请输入原料长度">
                                </div>
                                <div class="form-group">
                                    <label>米重/厚度</label>
                                    <input type="number" step="0.1" name="matHeight"
                                           class="form-control"
                                           placeholder="请输入原料米重/厚度">
                                </div>
                                <div class="form-group">
                                    <label>库位</label>
                                    <select class="form-control" name="whiId">
                                        <option value="">请选择</option>
                                        <option th:each="type:${warehouse}" th:value="${type.whiId}"
                                                th:text="${type.whiName}"
                                                th:selected="${type.whiName eq '原料库'}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>在库类型</label>
                                    <select name="ityInType" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="1">库存在库</option>
                                        <option value="2">项目在库</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>原料分类</label>
                                    <select name="materialKind" class="form-control ">
                                        <option value="型材">型材</option>
                                        <option value="板材">板材</option>
                                        <option value="" selected="selected">全部</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"><span
                                        class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;

    /** 打开库存修改模态框 */
    function edit(id, d) {
        $("#ityId").val(id);
        $("#ityProName").val(d.ityProName);
        $("#itySpec").val(d.itySpec);
        $("#ityBackDate").val(d.ityBackDate);
        js.modal.open("modal-create");
    }

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "matInvManage/complex/list",
            pageSize: 300,
            showExport: false,
            columns: [
                {
                    title: '序号', field: '', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '物料描述', field: 'matNameDesc', width: "200"},
                {title: '数量', field: 'ityNum'},
                {
                    title: '单价<br>（元）', field: 'ityPrice',
                    formatter: function (value, row, index) {
                        if (hasP("matinv:amount:view")) {
                            if (value == undefined || value == null || value == 0) {
                                return "--"
                            } else {
                                return value;
                            }
                        } else {
                            return '***';
                        }
                    }
                },
                {
                    title: '金额<br>（元）', field: 'ityAmount',
                    formatter: function (value, row, index) {
                        if (hasP("matinv:amount:view")) {
                            if (value == undefined || value == null || value == 0) {
                                return "--"
                            } else {
                                return value;
                            }
                        } else {
                            return '***';
                        }
                    }
                },
                {title: '理论重量', field: 'ityWeight'},
                {title: '跟踪号', field: 'ityTrackCode', width: "100"},
                {title: '特殊说明', field: 'itySpec'},
                {title: '项目编号', field: 'ityProCode'},
                {title: '项目名称', field: 'ityProName', width: "220"},
                {title: '回货时间', field: 'ityBackDate'},
                {
                    title: '在库类型', field: 'ityInType',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '库存在库';
                        } else if (value === 2) {
                            return '项目在库';
                        }
                    }
                },
                {
                    title: '操作', width: '80',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP("matinv:matinvedit:edit")) {
                            actions.push("<a class='btn btn-warning btn-xs'  href='javascript:void(0);' onclick='edit(" + row.ityId + "," + JSON.stringify(row) + ")'>修改</a>");
                        }
                        return actions.join('');
                    }
                }
            ],
            rowStyle: function (row, index) {
                if (row.itySpec != null && row.itySpec.indexOf("不合格") >= 0) {
                    return {css: {"color": "red"}}
                } else {
                    return {css: {"color": "black"}}
                }
            }
        });

        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /** 保存库存信息编辑 */
        $("#btn-editInventory").click(function () {

            js.post({
                url: ctx + "material/inventoryEdit/editCheck",
                data: $("#editForm").serialize(),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.confirm(result.msg == "合并" ? "该记录将被与其他相同类型库存合并，确定修改吗？" : "确认修改该记录吗？", function (result) {
                            js.validSubmit({
                                formId: "editForm",
                                url: ctx + "material/inventoryEdit/edit",
                                data: new FormData($("#editForm")[0]),
                                success: function (result) {
                                    if (result.type === web_status.SUCCESS) {
                                        js.modal.hide("modal-create");
                                        js.modal.success("操作成功");
                                        js.table.refresh(table);
                                    }
                                }
                            });
                        })
                    } else {
                        var ss = "操作失败！原因：该条库存记录" + result.msg;
                        js.modal.warning(ss);
                    }
                }
            });


        })

        /** 库存信息编辑验证 */
        js.validate.init("editForm", {
            fields: {
                ityProName: {validators: {notEmpty: {message: '请输入项目名称'}}},
            }
        });

        /** 关闭修改模态框 */
        js.modal.hideEvent("modal-create", function () {
            js.reset("editForm");
            js.validate.reset("editForm");
        });
    });
</script>
</body>
</html>
